package com.jwgf.common;

import android.os.SystemClock;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class SuCommand {
    /**
     * su替代方案
     */
    public static synchronized void suClient(final String cmd) {
        new Thread("suClientThread") {
            @Override
            public void run() {
                try {
                    DatagramSocket socket = new DatagramSocket(0);
                    byte[] bytes = cmd.getBytes();
                    socket.send(new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 23123));
                    socket.disconnect();
                    socket.close();
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
        // 等待socket执行留一点时间
        SystemClock.sleep(200);
    }
}
